﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "5%", sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '会员姓名', name: 'MemberName', width: "10%", sortable: false, align: 'left' },
                    { display: '电话', name: 'MemberPhone', width: "10%", sortable: false, align: 'left' },
                    { display: '提现金额', name: 'OutPay', width: "10%", sortable: false, align: 'left', process: formatAmt },
                    //{ display: '提现方式', name: 'BankName', width: "10%", sortable: false, align: 'left' },
                    { display: '提现时间', name: 'CreateTime', width: "10%", sortable: false, align: 'left' },
                     { display: '银行名称', name: 'BankName', width: "10%", sortable: false, align: 'left' },
                    { display: '银行卡号', name: 'BankCardNo', width: "10%", sortable: false, align: 'left' },
                    { display: '状态', name: 'StatusName', width: "10%", sortable: false, align: 'left' }
                    //{ display: '操作', name: 'Id', width: "10%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);

        //function formatNum(num) {
        //    if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)) { alert("wrong!"); return num; }
        //    var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
        //    var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
        //    while (re.test(b)) b = b.replace(re, "$1,$2$3");
        //    return a + "" + b + "" + c;
        //}
        function formatNum(v) {
            if (isNaN(v)) {
                return v;
            }
            v = (Math.round((v - 0) * 100)) / 100;
            v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v
                    + "0" : v);
            v = String(v);
            var ps = v.split('.');
            var whole = ps[0];
            var sub = ps[1] ? '.' + ps[1] : '.00';
            var r = /(\d+)(\d{3})/;
            while (r.test(whole)) {
                whole = whole.replace(r, '$1' + ',' + '$2');
            }
            v = whole + sub;

            return v;
        }

        function formatAmt(value, cell) {
            return "<span style='text-decoration:none;' class='abtn' >" + formatNum(value) + "</span>";

        }

        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });

        //导出Excel
        $("#btnExport").click(function (e) {
            $.post(options.exportUrl, { id: "" },
                    function (res) {
                        if (res.Status > 0) {
                            alert("操作成功！");
                            xjgrid.Reload();
                        }
                        else {
                            alert("操作失败！");
                        }
                    },
                    "json"
              );
        });

    });

})(window, undefined, jQuery);